package team.common.config;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;


  
/**
 * @author  alex
 */
public class ConfigManager extends PropertiesConfiguration {
    
    public static char DELIMITER_CHAR = ';';
    public static String ENCODING = "UTF-8";
    /**
	 * @uml.property  name="instance"
	 * @uml.associationEnd  
	 */
    private static ConfigManager instance = null;
  
    /**
	 * @return
	 * @uml.property  name="instance"
	 */
    public static ConfigManager getInstance() {

        return instance;
    }
    

    public synchronized static void init(String fileName) throws ConfigurationException {

        setDefaultListDelimiter(DELIMITER_CHAR);
        instance = new ConfigManager(fileName);
    }
    

    /**
     * private constructor
     */
    private ConfigManager() {

        super();
    }
    

    private ConfigManager(String fileName) throws ConfigurationException {

        super(fileName);
        
        setEncoding(ENCODING);
        setReloadingStrategy(new FileChangedReloadingStrategy());
    }
    

    @Override
    
    public String getString(String key) {

        String tempValue = "";
        
        try {
            tempValue = new String(getInstance().getString(key, "").getBytes("ISO-8859-1"), "UTF-8");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        
        return tempValue;
    }

}
